# !/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File    :   test.py
@Time    :   2025/01/17 20:59:53
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@python_requires    :   None
@Desc    :   None
'''


# 写出支持Chain().users('michael').repos 的链式调用：


class Chain2(object):
    def __init__(self, path=''):
        self._path = path

    def __getattr__(self, name):
        return Chain2('%s/%s' % (self._path, name))

    def __str__(self):
        return self._path

    __repr__ = __str__

    # def users(self, name):
    #     return Chain2('%s/users/%s' % (self._path, name))

    # def repos(self):
    #     return Chain2('%s/repos' % self._path)

    # 请在 Chain2 类中实现 __call__ 方法，使得 Chain().users('michael').repos() 等价于 Chain2('users/michael/repos')

    def __call__(self, *args, **kwargs):
        return Chain2('%s/%s' % (self._path, '/'.join(map(str, args))))

    # 请在 Chain2 类中实现 __getitem__ 方法，使得 Chain().users('michael')[0] 等价于 Chain2('users/michael/0')

    def __getitem__(self, item):
        return Chain2('%s/%s' % (self._path, item))#拼索引
        # return Chain2('%s/%s/%s' % (self._path, '/'.join(map(str, self._path.split('/')[:-1])), item))

# print('Chain2().users(\'michael\').repos(): ',
#       Chain2().users('michael').repos())

# print('Chain2().users(\'michael\')[0]: ',  Chain2().users('michael')[0].status)

# print('Chain2().users(\'michael\')[\'repos\']: ',
#       Chain2().users('michael')['repos'])



